<?php
/**
 * Created by PhpStorm.
 * User: zhangbing
 * Date: 2017/5/20
 * Time: 16:16
 */
namespace app\api\validate;
use think\Validate;

class User extends Validate{
    //定义验证规则
    protected $rule = [
        'username' => 'require|number|length:11|unique:user',
        'password' => 'require|length:6,18',
        'nickname' => 'require|max:20|unique:user',
        'sex'      => 'require',
        'birth'    => 'require|length:10',
    ];

    //定义错误信息
    protected $message = [
        'username.require' => '请输入手机号',
        'username.number'  => '手机号必须为数字',
        'username.length'  => '手机号必须为11位数字',
        'username.unique'  => '您的帐号已存在',
        'password.require' => '密码不能为空',
        'password.length'  => '密码长度为6-18位',
        'nickname.require' => '请输入昵称',
        'nickname.max'     => '昵称不能超过20个字符',
        'nickname.unique'  => '该昵称已存在',
        'sex.require'      => '性别不能为空',
        'birth.require'    => '请输入出生日期',
        'birth.length'     => '出生日期格式为2017-08-08',
    ];

    //验证场景
    protected $scene = [
        'login'          => ['username.require','username.number','username.length','password'],
        'forgetPassword' => ['username.require','username.number','username.length','password'],
        'checkNickname'  => ['nickname'],
        'checkUser'      => ['username','password'],
        'register'       => ['username','password','nickname','sex','birth'],
        'updateNickname' => ['nickname'],
    ];
}
